import React from "react";

// Navigate是用来做路由重定向的
import { Link, Routes, Route, Navigate, Outlet } from "react-router-dom";
import "./07-style.css";

const Classify = () => {
  return <div>分类页面</div>;
};
const Hot = () => {
  return <div>热销页面</div>;
};

const Home = () => {
  return (
    <>
      <div>这是首页</div>
      <ul>
        <li>
          <Link to="/home/classify">分类页</Link>
        </li>
        <li>
          <Link to="/home/hot">热销页</Link>
        </li>
      </ul>

      <hr />

      {/* 相当于vue的router-view */}
      <Outlet />
    </>
  );
};
const About = () => {
  return <div>这是关于页</div>;
};

const App = () => {
  return (
    <>
      <h2>路由重定向</h2>
      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
      </ul>
      <ul>
        <li>
          <Link to="/about">关于页</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/" element={<Navigate to="/home"></Navigate>}></Route>
        <Route path="/home" element={<Home />}>
          <Route
            path="/home"
            element={<Navigate to="/home/classify"></Navigate>}
          ></Route>
          <Route path="/home/classify" element={<Classify />}></Route>
          <Route path="/home/hot" element={<Hot />}></Route>
        </Route>
        <Route path="/about" element={<About />}></Route>
      </Routes>
    </>
  );
};

export default App;
